package top.infopub.mgr.cap.web;

import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.infopub.mgr.cap.domain.ContractDomain;
import top.infopub.mgr.cap.service.FinancingContractService;
import top.infopub.mgr.cap.vo.LookInfoBeginVo;
import top.infopub.mgr.common.page.ParamPage;
import top.infopub.mgr.common.vo.RspVo;
import top.infopub.mgr.mkt.service.MarketManageService;
import top.infopub.model.hr.OrgInfo;
import top.infopub.model.hr.StaffInfo;
import top.infopub.security.util.SessionUserUtils;
import top.infopub.security.vo.AuthorizationVO;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/financingContract")
public class FinancingContractController {

    @Autowired
    private MarketManageService marketManageService;

    @Autowired
    private FinancingContractService financingContractService;
    /**
     * 总合同管理列表
     * @return
     */
    @RequestMapping("/list")
    public String list(HttpServletRequest request) {
        //获取登录人员信息
        AuthorizationVO vo = SessionUserUtils.getSessionAttributeForUserDtl();
        //查询区域公司列表
        List<OrgInfo> orgInfoList = marketManageService.queryOrgInfoByAuthUserId(vo);
        request.setAttribute("orgInfoList", orgInfoList);
        return "cap/lay-contract-list";
    }

    @RequestMapping("/contractList")
    public String bidManageList(HttpServletRequest request) {
        //获取登录人员信息
        AuthorizationVO vo = SessionUserUtils.getSessionAttributeForUserDtl();
        //查询区域公司列表
        List<OrgInfo> orgInfoList = marketManageService.queryOrgInfoByAuthUserId(vo);
        request.setAttribute("orgInfoList", orgInfoList);
        //查询营销人员列表
        List<StaffInfo> staffInfoList = marketManageService.queryStaffInfoByAuthUserId(vo);
        request.setAttribute("staffInfoList", staffInfoList);
        return "cap/lay-contract-list";
    }
    /**
     * 合同管理台账列表数据
     * @return
     */
    @RequestMapping("/queryContractByCondition")
    @ResponseBody
    public RspVo<ContractDomain> queryFinancingByCondition(LookInfoBeginVo lookInfoBeginVo, ParamPage paramPage) {
        Page<ContractDomain> page = new Page<ContractDomain>();
        page.setPageNum(paramPage.getPage());
        page.setPageSize(paramPage.getLimit());
        page = financingContractService.selectFinByDomainWhere(page, lookInfoBeginVo);
        return RspVo.getSuccessResponse(page.getTotal(), page.getResult());
    }
}
